package com.me.mygdxgame.models;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.me.mygdxgame.assets.Assets;

public class Item extends AbstractGameObject{

	private Texture texItem;
	private TextureRegion regItem;
	public boolean collected;
	private TextureRegion[] itemFrames;
	private TextureRegion[] temp;
	private float stateTime = 0;
	private Animation itemAnimation;
	
	public Item(){
		init();
	}
	
	private void init() {
//		texItem = Assets.item;
//		regItem = new TextureRegion(texItem, 0, 0, 40, 40);
//		sprite.setRegion(regItem);
		temp = TextureRegion.split(Assets.item, 40, 40)[0];
		itemFrames = getTextures(1, 5, temp);
		itemAnimation = new Animation(0.2f, itemFrames);
//		dimension.set(40, 40);
		sprite.setSize(40, 40);
//		bounds.set(0, 0, dimension.x, dimension.y);
		collected = false;
	}
	
	@Override
	public void render(SpriteBatch batch) {
		if(collected)return;
//		TextureRegion reg = null;
//		reg = regItem;
//		batch.draw(reg.getTexture(),
//				position.x, position.y,
//				origin.x, origin.y,
//				dimension.x, dimension.y,
//				scale.x, scale.y,
//				rotation,
//				reg.getRegionX(), reg.getRegionY(),
//				reg.getRegionWidth(), reg.getRegionHeight(), 
//				false, false
//				);
		sprite.setRegion(itemAnimation.getKeyFrame(stateTime, true));
		sprite.draw(batch);
	}

	@Override
	public void update(float deltaTime) {
		super.update(deltaTime);
		stateTime += deltaTime;
	}

}
